a=int(input())
maxprost=0
countd=0
if a<1000 or a>9999:
    print("0")
else:
    d1=a//1000
    d2=a//100%10
    d3=a//10%10
    d4=a%10
    for i in range(1,d1+1):
        if d1%i==0:
            countd+=1
    if countd==2 and d1>=maxprost:
        maxprost=d1
    countd=0
    for i in range(1,d2+1):
        if d2%i==0:
            countd+=1
    if countd==2 and d2>=maxprost:
        maxprost=d2
    countd=0
    for i in range(1,d3+1):
        if d3==0:
            countd+=1
    if countd==2 and d3>=maxprost:
        maxprost=d3
    countd=0
    for i in range(1,d4+1):
        if d4%i==0:
            countd+=1
    if countd==2 and d4>=maxprost:
        maxprost=d4
    chislo1=d1*10+d2
    chislo2=d1*100+d2*10+d3
    chislo3=d2*10+d3
    chislo4=d3*10+d4
    chislo5=d1*1000+d2*100+d3*10+d4
    countd=0
    for i in range(1,chislo1+1):
        if chislo1%i==0:
            countd+=1
    if countd==2 and chislo1>=maxprost:
        maxprost=chislo1
    countd=0
    for i in range(1,chislo2+1):
        if chislo2%i==0:
            countd+=1
    if countd==2 and chislo2>=maxprost:
        maxprost=chislo2
    countd=0
    for i in range(1,chislo3+1):
        if chislo3%i==0:
            countd+=1
    if countd==2 and chislo3>=maxprost:
        maxprost=chislo3
    countd=0
    for i in range(1,chislo4+1):
        if chislo4%i==0:
            countd+=1
    if countd==2 and chislo4>=maxprost:
        maxprost=chislo4
    countd=0
    for i in range(1,chislo5+1):
        if chislo5%i==0:
            countd+=1
    if countd==2 and chislo5>=maxprost:
        maxprost=chislo5
    print(maxprost)